package com.fr.chart.core.glyph;

import com.fr.base.core.GraphHelper;
import com.fr.base.core.json.JSONException;
import com.fr.base.core.json.JSONObject;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.chart.ChartGlyphLayout;
import com.fr.chart.base.equals.Equals;
import com.fr.chart.core.RectangleGlyph;
import com.fr.report.io.xml.ReportXMLUtils;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Paint;
import java.awt.RenderingHints;
import java.awt.geom.Rectangle2D;
import java.awt.geom.Rectangle2D.Double;
import java.awt.geom.RoundRectangle2D.Double;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class ChartGlyph extends RectangleGlyph
{
  private static final long serialVersionUID = -4023596592305921803L;
  public static final String XML_TAG = "ChartGlyph";
  private PlotGlyph plotGlyph;
  private LegendGlyph legendGlyph;
  private TextGlyph titleGlyph;
  private boolean isJSDraw = false;

  public void setPlotGlyph(PlotGlyph paramPlotGlyph)
  {
    this.plotGlyph = paramPlotGlyph;
  }

  public PlotGlyph getPlotGlyph()
  {
    return this.plotGlyph;
  }

  public void setLegendGlyph(LegendGlyph paramLegendGlyph)
  {
    this.legendGlyph = paramLegendGlyph;
  }

  public LegendGlyph getLegendGlyph()
  {
    return this.legendGlyph;
  }

  public void setTitleGlyph(TextGlyph paramTextGlyph)
  {
    this.titleGlyph = paramTextGlyph;
  }

  public TextGlyph getTitleGlyph()
  {
    return this.titleGlyph;
  }

  public void setJSDraw(boolean paramBoolean)
  {
    this.isJSDraw = paramBoolean;
  }

  public boolean isJSDraw()
  {
    return this.isJSDraw;
  }

  public Iterator selectableChildren()
  {
    ArrayList localArrayList = new ArrayList();
    if (this.plotGlyph != null)
      localArrayList.add(this.plotGlyph);
    if (this.legendGlyph != null)
      localArrayList.add(this.legendGlyph);
    if (this.titleGlyph != null)
      localArrayList.add(this.titleGlyph);
    return localArrayList.iterator();
  }

  public Image toImage(int paramInt1, int paramInt2)
  {
    BufferedImage localBufferedImage = GraphHelper.createBufferedImage(paramInt1, paramInt2, 6);
    Graphics2D localGraphics2D = localBufferedImage.createGraphics();
    if (isRoundBorder())
      setBounds(new RoundRectangle2D.Double(0.0D, 0.0D, paramInt1, paramInt2, 10.0D, 10.0D));
    else
      setBounds(new Rectangle2D.Double(0.0D, 0.0D, paramInt1, paramInt2));
    draw(localGraphics2D);
    localBufferedImage.flush();
    localGraphics2D.dispose();
    return localBufferedImage;
  }

  public void draw(Graphics paramGraphics)
  {
    Graphics2D localGraphics2D = (Graphics2D)paramGraphics;
    Paint localPaint = localGraphics2D.getPaint();
    super.draw(paramGraphics);
    Object localObject = localGraphics2D.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
    localGraphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    localGraphics2D.translate(getBounds().getX(), getBounds().getY());
    doLayout();
    if (this.plotGlyph != null)
      this.plotGlyph.draw(localGraphics2D);
    if (this.legendGlyph != null)
      this.legendGlyph.draw(localGraphics2D);
    if (this.titleGlyph != null)
      this.titleGlyph.draw(localGraphics2D);
    localGraphics2D.translate(-getBounds().getX(), -getBounds().getY());
    localGraphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, localObject);
    localGraphics2D.setPaint(localPaint);
  }

  public void doLayout()
  {
    ChartGlyphLayout localChartGlyphLayout = new ChartGlyphLayout();
    localChartGlyphLayout.setLayoutBounds(getBounds());
    localChartGlyphLayout.doLayout(this);
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    super.readXML(paramXMLableReader);
    if (paramXMLableReader.isChildNode())
    {
      String str1 = paramXMLableReader.getTagName();
      if ("LegendGlyph".equals(str1))
        this.legendGlyph = ((LegendGlyph)paramXMLableReader.readXMLObject(new LegendGlyph()));
      if ("PlotGlyph".equals(str1))
        this.plotGlyph = ((PlotGlyph)ReportXMLUtils.readXMLable(paramXMLableReader));
      if ("TextGlyph".equals(str1))
        this.titleGlyph = ((TextGlyph)paramXMLableReader.readXMLObject(new TextGlyph()));
      if ("ChartGlyphAttr".equals(str1))
      {
        String str2;
        if ((str2 = paramXMLableReader.getAttr("isJSDraw")) != null)
          setJSDraw(Boolean.valueOf(str2).booleanValue());
      }
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("ChartGlyph");
    super.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.startTAG("ChartGlyphAttr").attr("isJSDraw", this.isJSDraw).end();
    if (this.plotGlyph != null)
      ReportXMLUtils.writeXMLable(paramXMLPrintWriter, this.plotGlyph, "PlotGlyph");
    if (this.legendGlyph != null)
      this.legendGlyph.writeXML(paramXMLPrintWriter);
    if (this.titleGlyph != null)
      this.titleGlyph.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.end();
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof ChartGlyph))
      return false;
    ChartGlyph localChartGlyph = (ChartGlyph)paramObject;
    if (!(super.equals(localChartGlyph)))
      return false;
    if (!(Equals.equals(localChartGlyph.getPlotGlyph(), getPlotGlyph())))
      return false;
    if (!(Equals.equals(localChartGlyph.getTitleGlyph(), getTitleGlyph())))
      return false;
    if (!(Equals.equals(localChartGlyph.getLegendGlyph(), getLegendGlyph())))
      return false;
    return (localChartGlyph.isJSDraw == this.isJSDraw);
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    ChartGlyph localChartGlyph = (ChartGlyph)super.clone();
    if (this.legendGlyph != null)
      localChartGlyph.legendGlyph = ((LegendGlyph)this.legendGlyph.clone());
    if (this.titleGlyph != null)
      localChartGlyph.titleGlyph = ((TextGlyph)this.titleGlyph.clone());
    if (this.plotGlyph != null)
      localChartGlyph.plotGlyph = ((PlotGlyph)this.plotGlyph.clone());
    return localChartGlyph;
  }

  public JSONObject toJSONObject()
    throws JSONException
  {
    JSONObject localJSONObject = super.toJSONObject();
    if (this.plotGlyph != null)
    {
      localJSONObject.put("plotType", this.plotGlyph.getPlotGlyphType());
      localJSONObject.put("plotGlyph", this.plotGlyph.toJSONObject());
    }
    if (this.legendGlyph != null)
      localJSONObject.put("legendGlyph", this.legendGlyph.toJSONObject());
    if (this.titleGlyph != null)
      localJSONObject.put("titleGlyph", this.titleGlyph.toJSONObject());
    return localJSONObject;
  }
}